<template>
  <div>
    <el-dialog
      title="编辑考场"
      :visible.sync="dialogVisible"
      width="40%"
      :show-close="false"
      :close-on-click-modal="false">
      <el-form ref="dataForm" :model="dataForm" :rules="dataForm_rules" label-width="110px">
        <el-form-item label="名称" prop="tr_name">
          <el-input v-model="dataForm.tr_name" size="small" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="考场代码" prop="tr_password">
          <el-input v-model="dataForm.tr_password" size="small" style="width: 80%"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="closeDialog">取 消</el-button>
      <el-button size="mini" type="primary" @click="updateInfo">确 定</el-button>
    </span>
    </el-dialog>
  </div>
</template>
<script>
  import{updateTestRoom} from "@/api/invigilate";
  export default{
    props:["isShowUpdateDialog","roomInfo"],
    data(){
      return {
        dialogVisible:this.isShowUpdateDialog,
        dataForm:JSON.parse(JSON.stringify(this.roomInfo)),

        dataForm_rules:{
          tr_name:[{ required: true, message: '不能为空', trigger: 'change' }],
          tr_password:[{ required: true, message: '不能为空', trigger: 'change' }]
        }
      }
    },

    methods:{
      closeDialog(){
        this.dialogVisible = false;
        this.$emit("closeDialog","update");
      },
      updateInfo(){
        this.$refs["dataForm"].validate((valid) => {
            if(valid){
              //提交信息
              updateTestRoom(this.dataForm).then(res=>{
                if(res.code == 200){
                  this.$message({
                    message: '修改成功',
                    type: 'success'
                  });
                  //关闭弹框
                  this.closeDialog();
                }
              });
            }
        });
      }
    }
  }
</script>

